package com.job.meeting.pojo;

import com.google.gson.Gson;
import com.job.meeting.controller.managementController;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Arrays;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class bookingTime implements Comparable<bookingTime> {
    private String date;
    private String beginTime;
    private String endTime;

    public bookingTime(String json) {
        bookingTime time = new Gson().fromJson(json, bookingTime.class);
        this.date = time.getDate();
        this.beginTime = time.getBeginTime();
        this.endTime = time.getEndTime();
    }

    public String getTime() {
        return date + "的" + beginTime + "——" + endTime;
    }

    //todo: 尚需测试
    @Override//优先级如下：date -> beginTime
    public int compareTo(bookingTime o) {
        int result = 0;

        //date的排序
        int[] self_date = new int[3];
        Arrays.setAll(self_date, x -> Integer.parseInt(this.date.split("-")[x]));
        int[] o_date = new int[3];
        Arrays.setAll(o_date, x -> Integer.parseInt(o.getDate().split("-")[x]));
        int[] date_compare = new int[3];
        Arrays.setAll(date_compare, x -> Integer.compare(self_date[x], o_date[x]));
        result = date_compare[0] != 0 ? date_compare[0] :
                date_compare[1] != 0 ? date_compare[1] : date_compare[2];

        //beginTime的排序
        if(result == 0)
        {
            result = Integer.compare(Integer.parseInt(this.beginTime.split(": ")[0]),
                    Integer.parseInt(o.getBeginTime().split(": ")[0]));
        }
        return result;
    }
}